package com.example.video.video_server.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.video.admin_server.entity.SysDict;
import com.example.video.common.exception.ServiceException;
import com.example.video.common.util.ResponseWrap;
import com.example.video.common.util.ResponseWrapUtil;
import com.example.video.video_server.entity.VideoBanner;
import com.example.video.video_server.service.IVideoBannerService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * banner表 前端控制器
 * </p>
 *
 * @author yj
 */
@RestController
@RequestMapping("/video/banner")
public class VideoBannerController {

    @Autowired
    private IVideoBannerService iVideoBannerService;

    @PostMapping("add")
    @ApiOperation("新增banner")
    public ResponseWrap add(@RequestBody VideoBanner videoBanner){
        boolean save = iVideoBannerService.save(videoBanner);
        return ResponseWrapUtil.success();
    }

    @PostMapping("update")
    @ApiOperation("修改banner")
    public ResponseWrap update(@RequestBody VideoBanner videoBanner){
        boolean save = iVideoBannerService.updateById(videoBanner);
        return ResponseWrapUtil.success();
    }

    @DeleteMapping("delete")
    @ApiOperation("删除banner")
    public ResponseWrap delete(Integer id){
        boolean remove = iVideoBannerService.removeById(id);
        return ResponseWrapUtil.success();
    }

    @GetMapping("getList")
    @ApiOperation("获取banner列表")
    public ResponseWrap getList(VideoBanner videoBanner){
        List banners = iVideoBannerService.list(new QueryWrapper<>(videoBanner).orderByAsc("sort"));
        return ResponseWrapUtil.success(banners);
    }

    @GetMapping("/getPaginationList")
    @ApiOperation(value = "条件分页查询banner列表")
    public ResponseWrap<Page<VideoBanner>> getPaginationList(@ApiParam("页面条数") Integer pageSize, @ApiParam("当前页")Integer pageIndex, VideoBanner videoBanner){
        Page<VideoBanner> page = iVideoBannerService.page(new Page<>(pageIndex, pageSize),new QueryWrapper<>(videoBanner).orderByDesc("sort"));
        return ResponseWrapUtil.success(page);
    }
}

